//
//  WKSingleVC.m
//  V-Learn
//
//  Created by Apple on 2019/5/20.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "WKSingleVC.h"
#import "SingleTableViewCell.h"
@interface WKSingleVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) NSString *content;
@end

@implementation WKSingleVC
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, LBNAVBAR_HEIGHT, ScreenW, ScreenH-LBNAVBAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"选择举报原因";
    [self.view addSubview:self.tableView];

    [self.tableView registerClass:[SingleTableViewCell class] forCellReuseIdentifier:@"Cell"];
    self.dataArray = @[@"存在违反国家法律法规的内容",@"存在辱骂,中伤,诽谤他人的内容",@"存在泄漏他人信息的内容",@"存在跨度,过渡宣传,站外联系方式内容",@"存在色情,淫秽,低俗等不适内容"];
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    UIView *footerView = [UIView new];
    footerView.frame = CGRectMake(0, 0, ScreenW, 100);
    self.tableView.tableFooterView = footerView;
    UIButton *btn = [[UIButton alloc] init];
    [btn setBackgroundImage:[UIImage imageNamed:@"wk_shadow_btn"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickJubaoBtn:) forControlEvents:UIControlEventTouchUpInside];
    [btn setTitle:@"确认举报" forState:UIControlStateNormal];
    [footerView addSubview:btn];
    [btn makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(44);
        make.centerX.mas_equalTo(footerView);
        make.centerY.mas_equalTo(footerView);
    }];
    
}
- (void)clickJubaoBtn:(UIButton *)sender{
    
    if (self.content.length==0||self.content==nil) {
        [MBProgressHUD showSuccess:@"请选择举报的内容" toView:self.view];
        return;
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"正在提交...";
    [hud show:YES];
    NSMutableDictionary *pagramsD = @{@"token":[UserModel getUserModel].token,@"opinionContent":self.content}.mutableCopy;
    [WYHXNetWorkService netWorkSerViceRequestWithPostUrl:WKMeCommitOptionRecord withPostParams:pagramsD withBlock:^(NSDictionary *result, NSError *error) {
        hud.hidden = YES;
        if ([result[@"code"]integerValue] == 200) {
            [MBProgressHUD showSuccess:@"举报成功等待管理员审核" toView:self.view];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [MBProgressHUD showSuccess:@"提交失败" toView:self.view];
        }
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SingleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.textLabel.text = @(indexPath.row).stringValue;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.textLabel.text = self.dataArray[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.content = [NSString stringWithFormat:@"%@", self.dataArray[indexPath.row]];
    NSLog(@"你选择的举报内容是：%@,", self.dataArray[indexPath.row]);
}

@end
